package com.ftm.dao.impl;

import java.util.List;

import com.ftm.tools.PageData;
import com.ftm.dao.EvaluateDao;
import com.ftm.entity.Evaluate;
import com.ftm.entity.Orders;
import com.ftm.entity.ShopEvaluate;
import com.ftm.tools.DBTools;

public class EvaluateDaoImpl implements EvaluateDao {
	/**
	 * 添加评价
	 */
	@Override
	public boolean addEvaluate(Evaluate evaluate) {
		if (evaluate!=null) {
			String sql="insert into ftm_evaluate values (null,?,?,?)";
			return DBTools.exUpdate(sql, evaluate.getUserid(),evaluate.getGoodsid(),evaluate.getEvaluate())>0;
		}
		return false;
	}
	/**
	 * 删除评价
	 */
	@Override
	public boolean delEvaluate(int evaluateid) {
		String sql="delete from ftm_evaluate where evaluateid = ? ";
		return DBTools.exUpdate(sql, evaluateid)>0;
	}
	/**
	 * 查询某一商品的所有评价
	 */
	@Override
	public List<Evaluate> queryEvaluate(int goodsid) {
		
		String sql="select * from ftm_evaluate where goodsid = ? ";
		List<Evaluate> list=(List<Evaluate>) DBTools.exQuery(sql, Evaluate.class, goodsid);
		//判断是否找到该商品的所有评价
		if (list.size()==0) {
			return null;
		}
		return list;
	}
	/**
	 * 分页查询
	 */
	@Override
	public PageData<Evaluate> queryPageEvaluate(int page, int pageSize, int goodsid) {
		// TODO Auto-generated method stub
		String sql="select * from ftm_evaluate where goodsid = ? ";
		
		return DBTools.exQueryByPage(sql, Evaluate.class, page, pageSize, goodsid);
	}
	/**
	 * 
	 */
	@Override
	public PageData<ShopEvaluate> queryPageshopEvaluate(int page, int pageSize, int shopid) {
		// TODO Auto-generated method stub
		String sql="select shopgoods.goodsname,ftm_evaluate.userid,ftm_evaluate.evaluate from ftm_evaluate,"+
				"(select * from ftm_goods where ftm_goods.shopid=?) as shopgoods "+
				"where ftm_evaluate.goodsid=shopgoods.goodsid";
		return DBTools.exQueryByPage(sql, ShopEvaluate.class, page, pageSize, shopid);
	}

}
